#include <linux/module.h>
#include<linux/timer.h>
MODULE_LICENSE("GPL");
struct timer_list my_timer; //声明动态定时器变量

// 自定义定时器到期执行的函数此函数在此只有显示的功能
void my_timer_function(unsigned long data)
{
	printk("In the my_timer_function\n");
	printk("the jiffies is :%ld\n", jiffies);    //显示当前节拍数
	struct timer_list *mytimer = (struct timer_list *)data;
	printk("the expries of my_timer1 is :%ld\n", mytimer->expires);

	// 显示定时器到期节拍数
	int result=try_to_del_timer_sync(&my_timer);
	printk("the try_to_del_timer_sync result is :%d\n", result);
}

int __init try_to_del_timer_sync_init(void)
{
	printk("my_timer will be created.\n");
	printk("the jiffies is :%ld\n", jiffies);      //显示当前节拍数
	init_timer(&my_timer);                         //初始化动态定时器
	my_timer.expires = jiffies + 1*HZ;            //HZ=250初始化字段expires
	my_timer.data = &my_timer;                     //初始化字段data
	my_timer.function = my_timer_function;         //初始化字段function
	add_timer(&my_timer);                          //激活动态定时器
	int result=try_to_del_timer_sync(&my_timer); //从链表中删除动态定时器
	printk("the try_to_del_timer_sync result is :%d\n", result);    //显示删除结果
	add_timer(&my_timer);                          //重新激活动态定时器
	printk("my_timer init.\n");
	return 0;
}

void __exit try_to_del_timer_sync_exit(void)
{
	int result=try_to_del_timer_sync(&my_timer);    //从链表中删除动态定时器
	printk("the try_to_del_timer_sync result is :%d\n", result);     //显示删除结果
	printk("Goodbye   try_to_del_timer_sync\n");
}

module_init(try_to_del_timer_sync_init);
module_exit(try_to_del_timer_sync_exit);



